<template>
  <a-select
    :placeholder="placeholder"
    show-search
    :filterOption="false"
    @focus="focus"
    @search="searchData"
    @popupScroll="scroll"
    :loading="searchLoading"
    v-model="id"
    v-bind="options"
    @change="selectItem"
  >
  
   <a-select-option v-if="NewisShow" :value="0">线下</a-select-option>
    <a-select-option v-if="isShow" :value="0">{{platform?'平台录入':'平台下单'}}</a-select-option>
    <a-select-option v-for="item in data" :value="item.id" :key="item.id">
      {{ item | getVehicleTypeName }}
    </a-select-option>
  </a-select>
</template>
<script>
// import {tableMixins} from '@/utils/mixins'
import { getNewAllChannel } from '@/api/store'

import {cloneDeep, debounce} from 'lodash'
export default {
  name: 'SelectVehicleType',
  props: {
    placeholder: {
      type: String,
      default: '请选择渠道'
    },
	platform:{
			type: Boolean,
			default: false
		},
		isShow:{
			type: Boolean,
			default: false
		},
    value: {
      type: [String, Number],
      default: undefined
    },
		NewisShow: {
		  type: Boolean,
		  value: false
		},
    options: {
      type: Object,
      default: () => ({})
    }
  },
  model: {
    prop: 'value',
    event: 'change'
  },
  data() {
    return {
      id: undefined,
      searchKey: '',
      searchLoading: false,
      data: [],
	  pageNum: 1,
	  rowsNum: 20,
	  total: 0,
    }
  },
  async created() {
    this.searchData = debounce(this.searchData, 800);
  },
  methods: {
    focus() {
      this.searchKey = ''
      this.pageNum = 1
      this.getData()
    },
	getId(){
			  this.id=undefined
	},
    cloneDeep,
    searchData(searchKey) {
      this.searchKey = searchKey
      this.pageNum = 1
      this.getData()
    },
    scroll(e) {
      const {scrollHeight, scrollTop, clientHeight} = e.target
      if (scrollHeight - scrollTop === clientHeight) {
				
        if (this.data.length === this.total) return
        this.pageNum++
        this.getData()
      }
    },
    selectItem(value) {
      this.$emit('change', value)
    },
    getData() {
      this.searchLoading = true
	  let data={
		  search: this.searchKey.trim(),
		  pageSize: this.rowsNum,
		  PageNo: this.pageNum,
		  isEnabled:true,
		  // isOnline:true
	  }
	  // this.NewisShow?'':data.isOnline=true
      getNewAllChannel(data).then(res => {
        this.searchLoading = false
        const {items, rowCount} = res
        this.data = this.pageNum === 1 ? items : this.data.concat(items)
        this.total = rowCount
      }).catch(() => this.searchLoading = false)
    }
  }
}
</script>
